package cn.qiao.zk.order.controller;

import cn.qiao.zk.order.ZookListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


/**
 * desc:
 *
 * @author qiao
 * @date 2023年05月05日 21:06
 */
@RestController
public class OrderController {


    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ZookListener listener;



    @RequestMapping(value = "/order/id",method = RequestMethod.GET)
    public String get(){
        //从zookeeper中获取调用的ip
        String path = listener.getPath();
        if(path == null){
            return "对不起，产品暂时停止服务！";
        }
        return restTemplate.getForObject("http://"+listener.getPath()+"/product/id",String.class);
    }


}
